<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<c:set var="buttons">
    <input type="button" style="margin-right: 5px"   onclick="f_add()" value="<fmt:message key="button.add"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_update()" value="<fmt:message key="button.update"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_delete()" value="<fmt:message key="button.delete"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_cancel()" value="<fmt:message key="button.cancel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_save()" value="<fmt:message key="button.save"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_query()" value="<fmt:message key="button.query"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_excel()" value="<fmt:message key="button.excel"/>"/>
	<input type="button" style="margin-right: 5px" onclick="f_cascadeAdd()"		value="<fmt:message key="button.cascadeAdd"/>" />
<c:if test='${not empty model.parentId}'>
    <input type="button" style="margin-right: 5px"   onclick="f_back()" value="<fmt:message key="button.back"/>"/>
</c:if>
</c:set>
<div id='toolbar' style="display:none">
<c:out value="${buttons}" escapeXml="false"/>
</div>
<c:set var="buttons">
	<input type="button" style="margin-right: 5px" onclick="f_add(subTable)"		value="<fmt:message key="button.add"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_update(subTable)"		value="<fmt:message key="button.update"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_delete(subTable)"		value="<fmt:message key="button.delete"/>" />
	<input type="button" style="margin-right: 5px" onclick="f_cancel(subTable)"		value="<fmt:message key="button.cancel"/>" />
</c:set>
<div id='subToolbar' style="display:none">
	<c:out value="${buttons}" escapeXml="false" />
</div>
<script>
Ext.onReady(globalScope._ready);
  var mainTable='<c:out value="${model.parameter.tableName}"/>'; 
  var subTable='T_EV_QUESTION';
  
Ext.onReady(function(){
  globalScope.grid.get(mainTable).on('rowdblclick',f_cascadeUpdate);
}); 


<c:if test='${not empty model.parentId}'>
function f_back(){
   globalScope._back();
}
</c:if>
function f_excel(){
  globalScope._exportExcel();
//  globalScope._excel();
}
function i_cascadePresave(mainTable,subTable,mainColumns,subColumns,form,rec){
    var w=form.getForm().findField('WEIGHT').getValue();
    var subGrid= globalScope.grid.get(subTable);
    var store=subGrid.getStore();
    var ww=0;
    store.each(function(r){
      var isValid=r.get('IS_VALID');
      if('Y'==isValid) ww+=parseFloat(r.get('WEIGHT'));
    });
    if(w!=ww){
      alert("评测问题权重之和("+ww+")与评测问题类权重("+w+")不一致！");
	  return false;
    }
	return true;
} 
 
function f_cascadeUpdate(){
  var grid=globalScope.grid.get(mainTable);
  var r=grid.getSelectionModel().getSelected();
  if(Ext.isEmpty(r)){
    Ext.Msg.alert('WARNING','请选择记录!');
    return;
  }
  globalScope.opt.add(mainTable,'cascadeUpdt');
  globalScope._cascade(mainTable,subTable,{tableName:subTable,REFID:r.id},r);
}

function f_cascadeAdd(){
  globalScope.opt.add(mainTable,'cascadeAdd');
  globalScope._cascade(mainTable,subTable,{tableName:subTable,REFID:'-1'},null);
}

function f_add(tableName){
  globalScope._add(tableName);
}

function f_update(tableName){
  globalScope._update(tableName);
}

function f_delete(tableName){
  globalScope._delete(tableName);
} 

function f_cancel(tableName){
  globalScope._cancel(tableName);
}

function f_save(tableName,url){
  globalScope._save(tableName,url);
}

function f_query(tableName){
    globalScope._query(tableName);
}
function f_gotoPage(pageNo,rowsOfPage,pageCount,rowCount,conditoin){
  globalScope._gotoPage({spanName:"g_pageSpan_<c:out value='${model.tableName}'/>",pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:conditoin,tableName:"<c:out value='${model.tableName}'/>"});
}
</script>
